// 权限模型
const { AuthOne, AuthTwo, AuthThree } = require('../../../models/auth');
// 统一数据返回类
const { DataReturn } = require('../../../common/returnclass');

/**
 * @api {Get} /auths 获取系统权限
 * @apiGroup Admin-Auths
 *
 * @apiSuccess {ObjectId} _id 权限id
 * @apiSuccess {String} authName 权限名称
 * @apiSuccess {String} icon  图标
 * @apiSuccess {Number} level  权限等级
 * @apiSuccess {String} path  权限路径
 * @apiSuccess {Array} children  子权限
 */
module.exports = async (req, res) => {

	// 查询所有权限信息
	let auths = await AuthOne.find().populate({
		path: 'children', model: AuthTwo ,
		populate: {
			path: 'children',
			model: AuthThree
		} 
	});
	if (!auths) return DataReturn.getData(res, 200, [], '获取角色列表失败');
	// 响应
	DataReturn.getData(res, 200, auths, '获取权限列表成功')
	

}
